<h1>Installing Trongate Using GitHub</h1>

<p>The Trongate PHP framework is available from GitHub at the following URL:</p>
<p><a href="https://github.com/trongate/trongate-framework">https://github.com/trongate/trongate-framework</a>.</p>

<p>However, the fastest and easiest way to obtain Trongate is by using the <strong>Trongate Desktop App</strong>. This Electron-based application, built with Node.js, is completely free and always will be. It is available for Mac, Windows, and Linux and can be downloaded from:</p>
<p><a href="https://trongate.io/download">https://trongate.io/download</a>.</p>

<h2>Why Use the Trongate Desktop App?</h2>
<p>The Trongate Desktop App provides several benefits, including:</p>
<ul>
    <li>Automatic framework downloads and setup</li>
    <li>Automatic updates when new features are released</li>
    <li>Automatic code generation</li>
    <li>Built-in database management</li>
    <li>A graphical query builder</li>
</ul>
<p><em>...and much more!</em></p>

<h2>Installing Without the Desktop App</h2>
<p>For those who prefer not to use the Desktop App, Trongate can still be installed manually.</p>

<h3>Configuring the Main Settings File</h3>
<p>To begin, the primary configuration file, <code>config.php</code>, must be set up correctly. This file is located at:</p>

[code]
  config/ 
    config.php 
[/code]

<p>The contents of <code>config.php</code> are as follows:</p>

[code=php]
<?php
// The main config file
define('BASE_URL', '');
define('ENV', 'dev');
define('DEFAULT_MODULE', 'welcome');
define('DEFAULT_CONTROLLER', 'Welcome');
define('DEFAULT_METHOD', 'index');
define('MODULE_ASSETS_TRIGGER', '_module');
define('INTERCEPT_404', 'trongate_pages/attempt_display');
[/code]

<p>The most critical setting at this stage is the <code>BASE_URL</code> constant.</p>

<h4>What is a Base URL?</h4>
<p>The <strong>Base URL</strong> (<code>BASE_URL</code>) represents the root address of a website. For example, if the site is hosted at <code>http://www.example.com/</code>, the <code>BASE_URL</code> should be set as follows:</p>

[code=php]
define('BASE_URL', 'http://www.example.com/');
[/code]

<div class="alert alert-success">
    <p>Always make sure the value that is assigned to <code>BASE_URL</code> ends with a forwardslash.</p>
</div>

<p>Ensuring that the base URL is correctly defined is essential for loading assets such as images and stylesheets and for proper navigation throughout the application.</p>

<p>After setting the <code>BASE_URL</code>, save the <code>config.php</code> file.</p>

<alert class="alert alert-info">
    <p><strong>Note:</strong> All constants defined in the <code>config</code> directory can be accessed from both controller and view files. For example, the following code outputs the application's base URL:</p>
[code=php]
echo BASE_URL;
[/code]
</alert>

<h3 class="mt-2">Setting Up the Database</h3>
<p>Users installing Trongate manually must create and configure a database.</p>

<h4>Step 1: The Database Configuration File</h4>
<p>Once a database has been created (using a database management tool such as PHPMyAdmin), the database configuration file (<code>database.php</code>) must be updated. This file is located at:</p>

[code]
  config/ 
    database.php 
[/code]

<p>The <code>setup.sql</code> file can be imported into the database management software to create the required tables. Alternatively, the SQL statements from <code>setup.sql</code> can be executed manually.</p>

<p>The content of <code>setup.sql</code> is as follows:</p>
[code]SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;

CREATE TABLE IF NOT EXISTS `trongate_administrators` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(65) DEFAULT NULL,
  `password` varchar(60) DEFAULT NULL,
  `trongate_user_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `trongate_administrators` (`id`, `username`, `password`, `trongate_user_id`) VALUES
(1, 'admin', '$2y$11$SoHZDvbfLSRHAi3WiKIBiu.tAoi/GCBBO4HRxVX1I3qQkq3wCWfXi', 1);

CREATE TABLE IF NOT EXISTS `trongate_comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `comment` text DEFAULT NULL,
  `date_created` int(11) DEFAULT 0,
  `user_id` int(11) DEFAULT NULL,
  `target_table` varchar(125) DEFAULT NULL,
  `update_id` int(11) DEFAULT NULL,
  `code` varchar(6) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `trongate_pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url_string` varchar(255) DEFAULT NULL,
  `page_title` varchar(255) DEFAULT NULL,
  `meta_keywords` text DEFAULT NULL,
  `meta_description` text DEFAULT NULL,
  `page_body` text DEFAULT NULL,
  `date_created` int(11) DEFAULT NULL,
  `last_updated` int(11) DEFAULT NULL,
  `published` tinyint(1) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `trongate_pages` (`id`, `url_string`, `page_title`, `meta_keywords`, `meta_description`, `page_body`, `date_created`, `last_updated`, `published`, `created_by`) VALUES
    (1, 'homepage', 'Homepage', '', '', '<div style=\"text-align: center;\">\n    <h1>It Totally Works!</h1>\n</div>\n<div class=\"text-div\">\n    <p>\n        <i>Congratulations!</i> You have successfully installed Trongate.  <b>This is your homepage.</b>  Trongate was built with a focus on lightning-fast performance, while minimizing dependencies on third-party libraries. By adopting this approach, Trongate delivers not only exceptional speed but also rock-solid stability.\n    </p>\n    <p>\n        <b>You can change this page and start adding new content through the admin panel.</b>\n    </p>\n</div>\n<h2>Getting Started</h2>\n<div class=\"text-div\">\n    <p>\n        To get started, log into the <a href=\"[website]tg-admin\">admin panel</a>. From the admin panel, you\'ll be able to easily edit <i>this</i> page or create entirely <i>new</i> pages. The default login credentials for the admin panel are as follows:\n    </p>\n    <ul>\n        <li>Username: <b>admin</b></li>\n        <li>Password: <b>admin</b></li>\n    </ul>\n</div>\n<div class=\"button-div\" style=\"cursor: pointer; font-size: 1.2em;\">\n    <div style=\"text-align: center;\">\n        <button onclick=\"window.location=\'[website]tg-admin\';\">Admin Panel</button>\n        <button class=\"alt\" onclick=\"window.location=\'https://trongate.io/docs\';\">Documentation</button>\n    </div>\n</div>\n<h2 class=\"mt-2\">About Trongate</h2>\n<div class=\"text-div\">\n    <p>\n        <a href=\"https://trongate.io/\" target=\"_blank\">Trongate</a> is an open source project, written in PHP. The GitHub repository for Trongate is <a href=\"https://github.com/trongate/trongate-framework\" target=\"_blank\">here</a>. Contributions are welcome! If you\'re interested in learning how to build custom web applications with Trongate, a good place to start is The Learning Zone. The URL for the Learning Zone is: <a href=\"https://trongate.io/learning-zone\" target=\"_blank\">https://trongate.io/learning-zone</a>. <b>If you enjoy working with Trongate, all we ask is that you give Trongate a star on <a href=\"https://github.com/trongate/trongate-framework\" target=\"_blank\">GitHub</a>.</b> It really helps!\n    </p>\n    <p>\n        Finally, if you run into any issues or you require technical assistance, please do visit our free Help Bar, which is at: <a href=\"https://trongate.io/help_bar\" target=\"_blank\">https://trongate.io/help_bar</a>.\n    </p>\n</div>', 1723807486, 0, 1, 1);

CREATE TABLE IF NOT EXISTS `trongate_tokens` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `token` varchar(125) DEFAULT NULL,
  `user_id` int(11) DEFAULT 0,
  `expiry_date` int(11) DEFAULT NULL,
  `code` varchar(3) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `trongate_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(32) DEFAULT NULL,
  `user_level_id` int(11) DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `trongate_users` (`id`, `code`, `user_level_id`) VALUES
(1, 'Tz8tehsWsTPUHEtzfbYjXzaKNqLmfAUz', 1);

CREATE TABLE IF NOT EXISTS `trongate_user_levels` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `level_title` varchar(125) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `trongate_user_levels` (`id`, `level_title`) VALUES
(1, 'admin');
COMMIT;[/code]

<p>This code should be executed, either by importing <code>setup.sql</code> or by copying and pasting the code above from within your database management software.</p>

<p>Once the database setup is complete, <strong>delete the <code>setup.sql</code> file</strong> to enhance security.</p>

